home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / yerk / mps231ss.hqx / Mops source / Nuc source / Defn.asm < prev    next >
Assembly Source File  |  1992-10-24  |  10KB  |  663 lines

  1. ; This file contains the definition of the macros and other items which
  2. ; generally define the structure of the implementation.
  3.  
  4.     mexp    0    ; Set non-zero for expansions
  5.  
  6. ;    =======================
  7.  
  8. ; Flag codes for various word types.  The actual values are quite
  9. ; arbitrary.
  10.  
  11. inline    equ    0
  12. docode    equ    1
  13. docol    equ    3
  14. docon    equ    5
  15. doval    equ    6
  16. doObj    equ    7
  17. dovbl    equ    8
  18. dovec    equ    9
  19. spec    equ    10
  20. xinfo    equ    11
  21. nocode    equ    12
  22. doObjPtr    equ    13
  23.  
  24. xinfoMk    equ    $4E58    ; This is  UNLK A0  which never appears in
  25.             ;  Mops code.
  26.  
  27. ;    ========================
  28.  
  29. FCBlen    equ    204
  30. HOLDlen    equ    30
  31. PADlen    equ    200
  32. TIBlen    equ    400
  33. ErrDumpLen    equ    200
  34. MaxDump    equ    (ErrDumpLen / 8) - 5
  35.  
  36. FBlkLen    equ    FCBlen + HOLDlen + PADlen + TIBlen + ErrDumpLen + 8
  37.                 ; The extra 8 is for the object header
  38.  
  39. ;    ========================
  40.  
  41. hbase    equ    0
  42.  
  43. ; Codes for handler routines.  These must all be negative.
  44.  
  45. inl_h    equ    -1
  46.  
  47. ; The following codes are used to table jump to the right routine within
  48. ; Handlers, and so must be even.
  49.  
  50. col_h    equ    -2
  51. call_h    equ    col_h
  52. const_h    equ    -4
  53. val_h    equ    -6
  54. create_h    equ    -8
  55. vect_h    equ    -10
  56. pm_h    equ    -12
  57. at_h    equ    -14
  58. store_h    equ    -16
  59. callstr_h    equ    -18
  60. reg_h    equ    -20
  61. obj_h    equ    -22
  62. does_h    equ    -24
  63. loc_h    equ    -26
  64. LitAddr    equ    -28
  65. PushDesc_h    equ    -30
  66. SPARE    equ    -32
  67. hLiteral    equ    -34
  68. CompExit    equ    -36
  69. CompJSRLong    equ    -38
  70. pif    equ    -40
  71. compPlLoop    equ    -42
  72. hmentry    equ    -44
  73. hplentry    equ    -46
  74. heb    equ    -48
  75. hStkObj    equ    -50
  76. hDoEx    equ    -52
  77. hgenaddr    equ    -54
  78. hgenxaddr    equ    -56
  79. class_h    equ    -58
  80. hcompimp    equ    -60
  81. objPtr_h    equ    -62
  82. bit_h    equ    -64
  83. swap_h    equ    -66
  84. hLoadBA    equ    -68
  85. FixDoes    equ    -70
  86. hPatch    equ    -72
  87. Floc_h    equ    -74
  88. Fcon_h    equ    -76
  89. Fval_h    equ    -78
  90. FP1_h    equ    -80
  91. FP2_h    equ    -82
  92. FPcmp_h    equ    -84
  93. hcompFPUL    equ    -86
  94. FCRcon_h    equ    -88
  95. class_in_mod_h    equ    -90
  96. imported_h    equ    -92
  97. hColA    equ    -94
  98. shift_h    equ    -96
  99. hDefnEnd    equ    -98
  100. Fat_h    equ    -100
  101. Fst_h    equ    -102
  102. builds_h    equ    -104
  103. MultDiv_h    equ    -106
  104.  
  105.  
  106. ;        =======================
  107.  
  108. ;                MACROS
  109.  
  110. ;        =======================
  111.  
  112. ; Push and pop macros - modified to use A6 instead of A7.
  113.  
  114. push.b    macrox    &1
  115.     move.b    &1,-(a6)
  116.     endm
  117.  
  118. push.w    macrox    &1
  119.     move.w    &1,-(a6)
  120.     endm
  121.  
  122. push    macrox    &1
  123.     move.w    &1,-(a6)
  124.     endm
  125.  
  126. push.l    macrox    &1
  127.     move.l    &1,-(a6)
  128.     endm
  129.  
  130. pop.b    macrox    &1
  131.     move.b    (a6)+,&1
  132.     endm
  133.  
  134. pop.w    macrox    &1
  135.     move.w    (a6)+,&1
  136.     endm
  137.  
  138. pop    macrox    &1
  139.     move.w    (a6)+,&1
  140.     endm
  141.  
  142. pop.l    macrox    &1
  143.     move.l    (a6)+,&1
  144.     endm
  145.  
  146.  
  147. ; Since we are using A5 as the module base reg, we need to reset it to CurrentA5
  148. ; over many system calls.  We also need to save RP (A7) in case the system calls
  149. ; us back (i.e. to a :PROC).  So here we define macros to set up for a system call
  150. ; then restore things after the system returns.
  151.  
  152. SavA5    macrox
  153.     jsr    DoSavA5-base(a3)
  154.     endm
  155.  
  156. RstA5    macrox
  157.     exg    a6,a7
  158.     move.l    (a7)+,a5
  159.     endm
  160.  
  161.  
  162. ; N assembles a push of the parameter as a literal number, with optimization.
  163.  
  164. N    macrox    &1
  165.     if    &1 = 0
  166.     CLR.L    -(A6)
  167.     else
  168.     if    (&1 < 128) or (-(&1) <= 128)
  169.     MOVEQ    #&1,D0
  170.     PUSH.L    D0
  171.     else
  172.     PUSH.L    #&1
  173.     endi
  174.     endi
  175.     endm
  176.  
  177.  
  178. ADD_M    macrox    &1
  179.     if    (&1 <= 8)
  180.     ADDQ.L    #&1,(A6)
  181.     else
  182.     ADDI.L    #&1,(A6)
  183.     endi
  184.     endm
  185.  
  186. SUB_M    macrox    &1
  187.     if    (&1 <= 8)
  188.     SUBQ.L    #&1,(A6)
  189.     else
  190.     SUBI.L    #&1,(A6)
  191.     endi
  192.     endm
  193.  
  194.  
  195. ; CONSTANTs - fetches of these are optimized, since we have the value
  196. ; available.
  197.  
  198. CONST    macrox    &1,&2,&3,&4    ; len, name, label, value
  199.     head    &1,&2,&3,docon
  200.     h    const_h
  201. &3    dc.l    &4
  202. &3_con    equ    &4
  203.     endm
  204.  
  205. NCONST    macrox    &1,&2    ; Constant with no head
  206.     nohead    &1,docon
  207.     h    const_h
  208. &1    dc.l    &2
  209. &1_con    equ    &2
  210.     endm
  211.  
  212.  
  213. FCon    macrox    &1
  214.     if    &1_con = 0
  215.     CLR.L    -(A6)
  216.     else
  217.     if    (&1_con < 128) or (-(&1_con) <= 128)
  218.     MOVEQ    #&1_con,D0
  219.     PUSH.L    D0
  220.     else
  221.     PUSH.L    &1-base(A3)
  222.     endi
  223.     endi
  224.     endm
  225.  
  226.  
  227. ; VALUEs - these have 3 "methods", fetch, increment, store.
  228.  
  229. VALU    macrox    &1,&2,&3,&4    ; len, name, label, value
  230.     head    &1,&2,&3,doval
  231.     h    val_h
  232.     if    "&4" <> ""
  233. &3    dc.l    &4
  234.     else
  235. &3    dc.l    0
  236.     endi
  237.     endm
  238.  
  239. NVALU    macrox    &1,&2    ; Value with no header
  240.     nohead    &1,doval
  241.     h    val_h
  242.     if    "&2" <> ""
  243. &1    dc.l    &2
  244.     else
  245. &1    dc.l    0
  246.     endi
  247.     endm
  248.  
  249. FVal    macrox    &1
  250.     PUSH.L    &1-base(A3)
  251.     endm
  252.  
  253. IncVal    macrox    &1
  254.     POP.L    D0
  255.     ADD.L    D0,&1-base(A3)
  256.     endm
  257.  
  258. ToVal    macrox    &1
  259.     POP.L    &1-base(A3)
  260.     endm
  261.  
  262. ZVal    macrox    &1
  263.     CLR.L    &1-base(A3)
  264.     endm
  265.  
  266.  
  267. ; Variables.  Note in this assembly we don't automatically allocate
  268. ; storage for a variable.  An explicit  byte n  or whatever must be
  269. ; done.
  270.  
  271. VARBL    macrox    &1,&2,&3,&4
  272.     head    &1,&2,&3,dovbl
  273.     h    create_h
  274. &3
  275.     endm
  276.  
  277. rVbl    macrox    &1
  278.     LEA    &1,A0
  279.     PUSH.L    A0
  280.     endm
  281.  
  282.  
  283. ; Vectors.  These have 3 "methods" - execute, fetch, store.
  284. ; System vectors have a default value, 4 bytes after the normal value.
  285. ; The normal value is a relocatable address, but we assume the default
  286. ; is within the normal dic range, so we use a straight JMP.
  287.  
  288. SVEC    macrox    &1,&2,&3,&4    ; len, name, label, default value
  289.     head    &1,&2,&3,dovec
  290.     h    vect_h
  291. &3    jsr    DoExVect-base(a3)
  292.     dc.l    0
  293.     if    "&4" <> ""
  294.     bra    &4
  295.     else
  296.     bra    null
  297.     endi
  298.     endm
  299.  
  300. NVEC    macrox    &1    ; Vector with no header and no default
  301.     nohead    &1,dovec
  302. &1    jsr    DoExVect-base(a3)
  303.     dc.l    0
  304.     endm
  305.  
  306.  
  307. ExVect    macrox    &1
  308.     jsr    &1-base(a3)
  309.     endm
  310.  
  311. ExVec    macrox    &1
  312.     ExVect    &1
  313.     endm
  314.  
  315. SetVect    macrox    &1,&2
  316.     lea    &1,a0
  317.     push.l    a0
  318.     lea    &2+4-base(a3),a0
  319.     jsr    DoToVect-base(A3)
  320.     endm
  321.  
  322. ClrVect    macrox    &1
  323.     clr.l    &1+4-base(a3)
  324.     endm
  325.  
  326.  
  327. ;        ================
  328.  
  329. pushop    macrox    &1
  330.     PUSH.W    &1-base(A3)
  331.     CLR.W    -(A6)
  332.     endm
  333.  
  334. compop    macrox    &1
  335.     pushop    &1
  336.     parms    wcomma
  337.     endm
  338.  
  339.  
  340. ; Compyl is the macro equivalent of COMPILE (now replaced by POSTPONE).
  341. ; It assembles a call to (COMP) which either moves in inline code or calls
  342. ; the compilation handler for the given word.
  343.  
  344. compyl    macrox    &1
  345.     rVbl    &1
  346.     bsr    doPcomp
  347.     endm
  348.  
  349.  
  350. NEXT    macrox
  351.     rts
  352.     endm
  353.  
  354. H    macrox    &1
  355.     dc.w    &1
  356.     endm
  357.  
  358. INL    macro    &1
  359.     dc.w    .xx-*-2
  360. &1    &1_m
  361. .xx    rts
  362.     endm
  363.  
  364. USE    macrox    &1
  365. &1    &1_m
  366.     rts
  367.     endm
  368.  
  369.  
  370. TOKEN    macrox    &1
  371.     if    &1_t = inline
  372.     &1_m
  373.     else
  374.     if    (&1_t = doval) or (&1_t = doObjPtr)
  375.     FVal    &1
  376.     else
  377.     if    &1_t = docon
  378.     FCon    &1
  379.     else
  380.     if    (&1_t = dovbl) or (&1_t = doObj)
  381.     rVbl    &1
  382.     else
  383.     if    &1_t = dovec
  384.     ExVec    &1
  385.     else
  386.     BSR    &1
  387.     endi
  388.     endi
  389.     endi
  390.     endi
  391.     endi
  392.     endm
  393.  
  394.  
  395. HCODE    macrox    &1,&2
  396.     if    "&2" <> ""
  397.     dc.w    &2
  398.     else
  399.     dc.w    &1
  400.     endi
  401.     endm
  402.  
  403.  
  404. ; CODE is called by HEAD and NOHEAD.
  405. ; It's easily the most complex macro here, so I'd better give some commentary:
  406. ; The first if..endi section handles the case where we need a descriptor pushed
  407. ; at compile-time.  This is indicated by the "pushDesc_h" handler code.  Then
  408. ; comes the xinfoMk which tells EXECUTE that this isn't code, then the byte count
  409. ; of the extra info, which in this case is 2 bytes for the descriptor type & subtype,
  410. ; and 2 bytes for the "real" handler code.
  411. ;
  412. ; Next we get rid of the case where there are no parameters after &1.
  413. ; Then after that we deal with all the mutually exclusive special cases with
  414. ; nested if..endi sections.
  415.  
  416. CODE    macrox    &1,&2,&3,&4    ; label,flag,opt,alt-hndlr-code
  417.     if    "&3" <> ""
  418.     dc.w    pushDesc_h
  419.     dc.w    xinfoMk
  420.     dc.w    4
  421.     dc.w    &3
  422.     endi
  423.  
  424.     if    "&2" = ""
  425. &1_t    set    docode
  426.     Hcode    call_h,&4
  427. &1
  428.     else
  429.  
  430. &1_t    set    &2
  431.  
  432.     if    &2 = inline
  433.     inl    &1
  434.  
  435.     else
  436.  
  437.     if    &2 = doObj
  438.     Hcode    obj_h,&4
  439.     dc.w    6
  440.     dc.l    nilP_con
  441.     dc.w    -6
  442. &1
  443.     else
  444.  
  445.     if    &2 = doObjPtr
  446.     Hcode    objPtr_h,&4
  447. &1    dc.l    nilP_con
  448.     dc.l    0
  449.  
  450.     else
  451.  
  452.     if    &2 = xinfo
  453.     Hcode    call_h,&4
  454.     dc.w    xinfoMk
  455.     dc.w    &1-*-2
  456.  
  457.     else
  458.  
  459.     if    ( &2 = docode ) or ( &2 = spec ) or ( &2 = docol ) or ( &2 = nocode )
  460.     Hcode    call_h,&4
  461. &1
  462.     endi
  463.     endi
  464.     endi
  465.     endi
  466.     endi
  467.     endi
  468.     endm
  469.  
  470.  
  471. linkit    macrox    &1
  472.     if    q%1 = 0
  473.     dc.l    0
  474.     else
  475.     dc.l    q%1+d-*
  476.     endi
  477. q%1    set    *-d-4
  478.     endm
  479.  
  480. ; The HEAD macro defines a dictionary header.
  481. ; The flag field identifies what kind of word this is.  If the flag is
  482. ; "docol", "inline", "spec" or null, it is a word that is called
  483. ; by a JSR, and we assemble the handler field and linking code here.
  484. ; If the flag is anything else, we assume that HEAD has been called from
  485. ; another macro that is looking after everything, so we just assemble the 
  486. ; header.
  487. ; The opt field is non-zero if this word can begin a sequence where
  488. ; optimization of the compiled code is zero.  The opt field is left in 
  489. ; 2 bytes at the start of the definition; at compile time this field is
  490. ; left in CompFlg.
  491.  
  492. HEAD    macrox    &1,&2,&3,&4,&5,&6 ; len-byte,name,label,flag,opt,alt-hdlr
  493.     align
  494.     loc
  495.     linkit    &1 and 7
  496.     dc.b    &1 or $80
  497.     text    &&2
  498.     align
  499.     code    &3,&4,&5,&6
  500.     endm
  501.  
  502.  
  503. NOHEAD    macrox    &1,&2,&3,&4    ; label, flag, opt, alt-hdlr
  504.     code    &1,&2,&3,&4
  505.     endm
  506.  
  507.  
  508. COMH    macrox    &1
  509.     MOVEQ    #&1,D0
  510.     PUSH.L    D0
  511.     parms    wcomma
  512.     endm
  513.  
  514. CALLH    macrox    &1
  515.     if    "&1" <> ""
  516.     MOVEQ    #&1,D0
  517.     endi
  518.     BSR    CallHandlers
  519.     endm
  520.  
  521. JUMPH    macrox    &1
  522.     if    "&1" <> ""
  523.     MOVEQ    #&1,D0
  524.     endi
  525.     BRA    CallHandlers
  526.     endm
  527.  
  528.  
  529. NOOPT    macrox
  530.     JSR    doNoOpt-base(A3)
  531.     endm
  532.  
  533.  
  534. PARMS    macrox    &1,&2,&3,&4,&5,&6
  535.     token    &1
  536.     IF    "&2" <> ""
  537.     token    &2
  538.     ENDI
  539.     IF    "&3" <> ""
  540.     token    &3
  541.     ENDI
  542.     IF    "&4" <> ""
  543.     token    &4
  544.     ENDI
  545.     IF    "&5" <> ""
  546.     token    &5
  547.     ENDI
  548.     IF    "&6" <> ""
  549.     token    &6
  550.     ENDI
  551.     endm
  552.  
  553.  
  554. BRANCH    macrox    &1
  555.     BRA.S    &1
  556.     endm
  557.  
  558. QBRANCH    macrox    &1
  559.     TST.L    (A6)+
  560.     BNE.S    &1
  561.     endm
  562.  
  563. ZBRANCH    macrox    &1
  564.     TST.L    (A6)+
  565.     BEQ.S    &1
  566.     endm
  567.  
  568. EQBRANCH    macrox    &1,&2
  569.     CMPI.L    #&1,(A6)+
  570.     BEQ.S    &2
  571.     endm
  572.  
  573. NEBRANCH    macrox    &1,&2
  574.     CMPI.L    #&1,(A6)+
  575.     BNE.S    &2
  576.     endm
  577.  
  578. msg    macrox    &1
  579.     JSR    pdotq-base(a3)
  580.     text    #&&1
  581.     align
  582.     endm
  583.  
  584. abq    macrox    &1
  585.     JSR    pabq
  586.     text    #&&1
  587.     align
  588.     endm
  589.  
  590.  
  591. ; testing *************
  592. ;
  593. ;d
  594. ;
  595. ;q0    set    0
  596. ;q1    set    0
  597. ;q2    set    0
  598. ;q3    set    0
  599. ;q4    set    0
  600. ;q5    set    0
  601. ;q6    set    0
  602. ;q7    set    0
  603. ;
  604. ;    dc.w    123
  605. ;
  606. ;    head    5,BLOGGS,bloggs
  607. ;    dc.l    9876
  608. ;
  609. ;    valu    4,HAHA,haha,25
  610. ;
  611. ; "Push a descriptor" test
  612. ;otCMP    equ    $26
  613. ;tsGE    equ    otCMP*256 + $C
  614. ;setTrue
  615. ;setFalse
  616. ;
  617. ;    head    2,>=,ge,docode,tsGE
  618. ;    CMPM.L    (A6)+,(A6)+
  619. ;    BGE.S    setTrue
  620. ;    BRA.S    setFalse
  621. ;
  622. ; Push a descriptor with inline
  623. ;nip_m    macrox
  624. ;    POP.L    (A6)
  625. ;    endm
  626. ;    head    3,NIP,nip,inline,tsCCOK
  627. ;
  628. ; "xinfo" test
  629. ;    head    3,YYY,yyy,xinfo
  630. ;    dc.w    123
  631. ;    dc.w    456
  632. ;yyy    moveq    #1,d0
  633. ;    rts
  634. ;
  635. ; xinfo with inline
  636. ;
  637. ;otADD    equ    $21
  638. ;
  639. ;plus_m    macrox
  640. ;    POP.L    D0
  641. ;    ADD.L    D0,(A6)
  642. ;    endm
  643. ;
  644. ;    head    1,+,plus,xinfo,,pm_h
  645. ;    dc.w    otADD
  646. ;    use    plus
  647. ;
  648. ;
  649. ;    head    7,LOCPARM,locparm,nocode,,loc_h
  650. ;
  651. ;
  652. ;    varbl    7,CONTEXT,context
  653. ;
  654. ;    dc.l    q0+d-*
  655. ;    dc.l    q1+d-*
  656. ;    dc.l    q2+d-*
  657. ;    dc.l    q3+d-*
  658. ;    dc.l    q4+d-*
  659. ;    dc.l    q5+d-*
  660. ;    dc.l    q6+d-*
  661. ;    dc.l    q7+d-*
  662. ;
  663. ;